home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1991 / number3 / dirsize.c < prev    next >
Text File  |  1991-06-13  |  1KB  |  46 lines

  1. #include <direct.h>
  2. #include <dos.h>
  3. #include <stdio.h>
  4.         void listfile(struct ffblk *filedata);
  5.         struct ffblk filedata;
  6.         long numClusters = 0;
  7.         int disk = 4; /* drive A=1, B-2,... */
  8.         long BytesPerCluster(int drive);
  9.         unsigned int clusterSize;
  10.  
  11. main()
  12. { long total= 0 ;
  13.   clusterSize = BytesPerCluster(disk);
  14.   if (findfirst("*.exe", &filedata, FA_ARCH) == 0)
  15.   {
  16.       printf("The files in the current directory are ...\n\n");
  17.       listfile(&filedata);
  18.       total += filedata.ff_fsize;
  19.       while (findnext(&filedata) == 0)
  20.       {
  21.          listfile(&filedata);
  22.          total += filedata.ff_fsize;
  23.       }
  24.       printf(" Total = %ld  numClusters = %ld clusterSize = %d\n",
  25.                total, numClusters, clusterSize);
  26.       printf(" Total disksize = %ld ", numClusters * clusterSize );
  27.   }
  28.   else perror("findfirst error");
  29. }
  30. void listfile(struct ffblk *filedata)
  31. {
  32.         printf("%-14s %8ld %8ld\n",
  33.               (filedata->ff_name),
  34.               (filedata->ff_fsize),
  35.               ((filedata->ff_fsize / clusterSize)+1 ));
  36.         numClusters += (filedata->ff_fsize / clusterSize)+1;
  37. }
  38.  
  39. long BytesPerCluster(int drive)
  40. { union REGS regs;
  41.   struct SREGS sregs;
  42.   regs.h.ah = 0x1C; regs.h.dl = drive;
  43.   if (intdosx(®s, ®s, &sregs) != -1)
  44.     return( (long) regs.h.al  * regs.x.cx );
  45. }
  46.